﻿#include "widgetcontrol.h"
#include "ui_widgetcontrol.h"

widgetControl::widgetControl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::widgetControl),
    loginWidget(new login_widget),
    faceLogin(new FaceLogin),
    regWidget(new register_widget)
    ,mainFunc(new MainFunction)
{
    qDebug("control");
    ui->setupUi(this);
    ConnectSlots();

}

widgetControl::~widgetControl()
{
    delete ui;
    delete loginWidget;
    delete faceLogin;
    delete regWidget;
    delete mainFunc;
    qDebug("control ~");
}

void widgetControl::start()
{
    qDebug("__88888");
    allTools::getHandPinfer();
    loginWidget->show();
}

void widgetControl::ConnectSlots()
{
    //login to faceLogin
    connect(loginWidget, SIGNAL(LoginToFaceLogin(QMap<QString,QString>)),
            this, SLOT(openFaceLogin(QMap<QString,QString>)));

    //login to register
    connect(loginWidget, SIGNAL(LogintoRegister()),
            this, SLOT(openRegWidget()));

    //facelogin to mainfunc
    connect(faceLogin, SIGNAL(FacetoMainFunc(QMap<QString,QString>)),
            this, SLOT(openMainFunc(QMap<QString,QString>)));

    //reg to mainfunc
    connect(regWidget, SIGNAL(RetoMainfunc(QMap<QString,QString>)),
            this, SLOT(openMainFunc(QMap<QString,QString>)));

    //mainFunc to Login
    connect(mainFunc, SIGNAL(toLogin()),
            this, SLOT(returnLogin()));

    //faceLogin to Login
    connect(faceLogin, SIGNAL(FacetoLogin()),
            this, SLOT(returnLogin()));

    //reg to Login
    connect(regWidget, SIGNAL(RetoLogin()),
            this, SLOT(returnLogin()));

    //closeAll
    connect(mainFunc, SIGNAL(closeAll()),
            this, SLOT(_close()));
    connect(loginWidget, SIGNAL(closeAll()),
            this, SLOT(_close()));


}

//获取信息并且展示
void widgetControl::openFaceLogin(QMap<QString,QString> res)
{
    faceLogin->UserInfo = res; //登录信息传给刷脸界面
   // qDebug() << res.size();
    faceLogin->showUserInfo();
    loginWidget->hide();
    faceLogin->show();
}

void widgetControl::openRegWidget()
{
    loginWidget->hide();
    regWidget->show();
}

void widgetControl::openMainFunc(QMap<QString,QString> res)
{
    mainFunc->UserInfo = res;
    mainFunc->UserPic = allTools::getAllFaceInfo();
    mainFunc->putUserInfo();

    faceLogin->hide();
    regWidget->hide();
    mainFunc->show();
}

void widgetControl::returnLogin()
{
    faceLogin->hide();
    regWidget->hide();
    mainFunc->hide();
    loginWidget->show();
}

void widgetControl::_close()
{
    allTools::destroyHandPinfer();
    if(allTools::getCap()->isOpened())
        allTools::getCap()->release();
    qApp->exit(0);
    qDebug("YES");
}

